package cn.vcjf.weapp.api.goods.entity;

import cn.vcjf.weapp.common.util.DateUtils;
import cn.vcjf.weapp.common.util.IdGen;
import cn.vcjf.weapp.common.web.JsonDateTypeConvert;
import cn.vcjf.weapp.common.web.PageModel;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.validator.constraints.NotBlank;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
    * 
    * </p>
 *
 * @author zhengzihang
 * @since 2018-09-25
 */
@TableName("vc_goods_order")
public class GoodsOrder extends PageModel<GoodsOrder> {

    /**
     * 1,普通,2,拼团,3,砍价,4套餐
     */
    public static int ORDER_TYPE_GEN = 1;
    public static int ORDER_TYPE_TEAM = 2;
    public static int ORDER_TYPE_CUT = 3;
    public static int ORDER_TYPE_COMBOS = 4;

    /**
     * 0,创建中.1,下单成功,待支付.2,已付款,待发货.3已发货.4已完成.5下单失败.6支付失败.7退款中,8已退款
     */
    public static int ORDER_STATUS_CREATING = 0;
    public static int ORDER_STATUS_WAITPAY = 1;
    public static int ORDER_STATUS_PAYED = 2;
    public static int ORDER_STATUS_SHIPPED = 3;
    public static int ORDER_STATUS_OK = 4;
    public static int ORDER_STATUS_UNORDER_FAILED = 5;
    public static int ORDER_STATUS_PAY_FAILED = 6;
    public static int ORDER_STATUS_REFUNDING = 7;
    public static int ORDER_STATUS_REFUNDED = 8;

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 客户id
     */
    @NotNull
    private Integer userId;

    /**
     * vc_goods_group表主键（商品具体规格）
     */
    private Integer goodsId;
    /**
     * 订单物品列表
     */
    @TableField(exist = false)
    List<GoodsOrderItem> orderItems;
    /**
     * 优惠券
     */
    @TableField(exist = false)
    private GoodsDiscount goodsDiscount;
    /**
     * 商品种类数量
     */
    @NotNull
    private Integer goodNum;
    /**
     * 收货人
     */
    @NotBlank
    private String userName;
    /**
     * 用户手机
     */
    @NotBlank
    private String phone;
    /**
     * 用户收货地址
     */
    @NotBlank
    private String userAddr;
    /**
     * 用户收货地址邮政编码
     */
    @NotBlank
    private String postCode;

    /**
     * 订单类型(1,普通,2,拼团,3,砍价,4套餐)
     */
    @NotNull
    private Integer orderType;

    /**
     * 批次订单号
     */
    private String batchOrderNo;

    /**
     * 订单编号
     */
    private String orderNo;

    /**
     * 拼团活动单号id
     */
    private Integer collageOrderId;

    /**
     * 订单金额
     */
    private BigDecimal traMoney;

    /**
     * 实际付款金额
     */
    private BigDecimal traActualMoney;

    /**
     * 优惠价格
     */
    private BigDecimal discountMoney;

    /**
     * 是否使用优惠券
     */
    private Integer isUseDiscount;

    /**
     * 优惠券ID
     */
    private Integer discountId;

    /**
     * 支付方式
     */
    private String payType;

    /**
     * 订单状态(0,创建中.1,下单成功,待支付.2,已付款,待发货.3已发货.4已完成.5下单失败.6支付失败.7退款)
     */
    private Integer status;
    /**
     * 状态描述
     */
    private String orderDes;
    /**
     * 唤起微信支付参数
     */
    private String payParams;
    /**
     * 支付返回
     */
    private String pResult;
    /**
     * 订单留言
     */
    private String remarks;
    /**
     * 付款时间
     */
    private Date payTime;
    /**
     * 订单名称
     */
    @TableField(exist = false)
    private String orderName;
    /**
     *快递公司
     */
    private String expressCompany;
    /**
     *快递单号
     */
    private String expressNo;
    /**
     *发货时间
     */
    private Date deliverTime;

    public String getExpressCompany() {
        return expressCompany;
    }

    public void setExpressCompany(String expressCompany) {
        this.expressCompany = expressCompany;
    }

    public String getExpressNo() {
        return expressNo;
    }

    public void setExpressNo(String expressNo) {
        this.expressNo = expressNo;
    }

    public Date getDeliverTime() {
        return deliverTime;
    }

    public void setDeliverTime(Date deliverTime) {
        this.deliverTime = deliverTime;
    }

    public String getPostCode() {
        return postCode;
    }

    public void setPostCode(String postCode) {
        this.postCode = postCode;
    }

    public String getOrderName() {
        return orderName;
    }

    public void setOrderName(String orderName) {
        this.orderName = orderName;
    }

    public Date getPayTime() {
        return payTime;
    }

    public void setPayTime(Date payTime) {
        this.payTime = payTime;
    }

    public List<GoodsOrderItem> getOrderItems() {
        return orderItems;
    }

    public void setOrderItems(List<GoodsOrderItem> orderItems) {
        this.orderItems = orderItems;
    }

    public String getOrderDes() {
        return orderDes;
    }

    public void setOrderDes(String orderDes) {
        this.orderDes = orderDes;
    }

    public String getPayParams() {
        return payParams;
    }

    public void setPayParams(String payParams) {
        this.payParams = payParams;
    }

    public String getpResult() {
        return pResult;
    }

    public void setpResult(String pResult) {
        this.pResult = pResult;
    }

    public GoodsDiscount getGoodsDiscount() {
        return goodsDiscount;
    }

    public void setGoodsDiscount(GoodsDiscount goodsDiscount) {
        this.goodsDiscount = goodsDiscount;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public Integer getGoodNum() {
        return goodNum;
    }

    public void setGoodNum(Integer goodNum) {
        this.goodNum = goodNum;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }
    public Integer getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(Integer goodsId) {
        this.goodsId = goodsId;
    }
    public String getUserAddr() {
        return userAddr;
    }

    public void setUserAddr(String userAddr) {
        this.userAddr = userAddr;
    }
    public Integer getOrderType() {
        return orderType;
    }

    public void setOrderType(Integer orderType) {
        this.orderType = orderType;
    }
    public String getBatchOrderNo() {
        return batchOrderNo;
    }

    public void setBatchOrderNo(String batchOrderNo) {
        this.batchOrderNo = batchOrderNo;
    }
    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }
    public Integer getCollageOrderId() {
        return collageOrderId;
    }

    public void setCollageOrderId(Integer collageOrderId) {
        this.collageOrderId = collageOrderId;
    }
    public BigDecimal getTraMoney() {
        return traMoney;
    }

    public void setTraMoney(BigDecimal traMoney) {
        this.traMoney = traMoney;
    }
    public BigDecimal getTraActualMoney() {
        return traActualMoney;
    }

    public void setTraActualMoney(BigDecimal traActualMoney) {
        this.traActualMoney = traActualMoney;
    }
    public BigDecimal getDiscountMoney() {
        return discountMoney;
    }

    public void setDiscountMoney(BigDecimal discountMoney) {
        this.discountMoney = discountMoney;
    }
    public Integer getIsUseDiscount() {
        return isUseDiscount;
    }

    public void setIsUseDiscount(Integer isUseDiscount) {
        this.isUseDiscount = isUseDiscount;
    }
    public Integer getDiscountId() {
        return discountId;
    }

    public void setDiscountId(Integer discountId) {
        this.discountId = discountId;
    }
    public String getPayType() {
        return payType;
    }

    public void setPayType(String payType) {
        this.payType = payType;
    }
    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @JsonSerialize(using = JsonDateTypeConvert.class)
    public Date getUnderTime(){ return createTime;}

    @TableField(exist = false)
    public static String[] preFix = {"GEN","CUT","TEAM","COM"};
    @TableField(exist = false)
    public static String[] ORDER_NAMES = {"普通","砍价","团购","套餐"};

    @Override
    public void preInsert(){
        super.preInsert();
        this.orderNo = preFix[orderType]+DateUtils.getDate("yyyyMMddHHmmss")+IdGen.getRandomString(3);
        this.status = ORDER_STATUS_CREATING;
        this.orderName = ORDER_NAMES[orderType]+"订单";
    }
    @Override
    public void preUpdate(){
        super.preInsert();
    }
    @Override
    public String toString() {
        return "GoodsOrder{" +
        "id=" + id +
        ", userId=" + userId +
        ", goodsId=" + goodsId +
        ", userAddr=" + userAddr +
        ", orderType=" + orderType +
        ", batchOrderNo=" + batchOrderNo +
        ", orderNo=" + orderNo +
        ", collageOrderNo=" + collageOrderId +
        ", traMoney=" + traMoney +
        ", traActualMoney=" + traActualMoney +
        ", discountMoney=" + discountMoney +
        ", isUseDiscount=" + isUseDiscount +
        ", discountId=" + discountId +
        ", payType=" + payType +
        ", status=" + status +
        ", createUser=" + createUser +
        ", createTime=" + createTime +
        ", updateUser=" + updateUser +
        ", updateTime=" + updateTime +
        ", deleteFlag=" + deleteFlag +
        ", sysUserId=" + sysUserId +
        "}";
    }
}
